package main

import (
	"github.com/gin-gonic/gin"
	"server/config"
	_ "server/data"
	"server/handlers/leetcode"
	"server/handlers/tank"
	"server/middleware"
	"server/utils"
	_ "server/utils"
)

func main() {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r.Use(middleware.CORSMiddleware())
	r.Use(middleware.Logger())

	api := r.Group("api")
	{
		// 力扣大赛API
		leetcodeApi := api.Group("leetcode")
		{
			leetcodeApi.GET("ranks", leetcode.Ranks)
		}

		// 坦克大战API
		tankApi := api.Group("tank")
		{
			// 获取车轮战排名
			tankApi.GET("ranks", tank.Ranks)
			// 获取决赛排名
			tankApi.GET("ranks/final", tank.FinalRanks)
			// 查询比赛是否存在 通过battle_id
			tankApi.GET("battle/isexists", middleware.AuthCookie(), tank.HavingBattleId)
			// 插入一场车轮战比赛信息
			tankApi.POST("rank", middleware.AuthCookie(), tank.CreateBattleInfo)
			// 宣布一场比赛无效
			tankApi.PATCH("rank/invalid", middleware.AuthCookie(), tank.InvalidBattleById)
			// 插入一场决赛比赛信息
			tankApi.POST("rank/final", middleware.AuthCookie(), tank.CreateFinalBattleInfo)
			// 实时推送接口
			tankApi.Any("ws", tank.WebSocketRanks)

		}

		y2023 := api.Group("y2023")
		{
			y2023.POST("regTeam", middleware.AuthCookie(), tank.RegTeam)
			//y2023.POST("unregTeam", middleware.AuthCookie(), tank.UnregTeam)
			y2023.GET("teamInfo", tank.TeamInfo)
			y2023.GET("teams", tank.Teams)
			y2023.POST("updateTeamFile", middleware.AuthCookie(), tank.UpdateTeamFile)
			y2023.POST("regMap", middleware.AuthCookie(), tank.RegMap)
			y2023.GET("maps", tank.Maps)
			y2023.POST("addGames", middleware.AuthCookie(), tank.AddGames)
			y2023.POST("addGame", middleware.AuthCookie(), tank.AddGame)
			y2023.GET("game", tank.GetGame)
			y2023.POST("gameRec", middleware.AuthCookie(), tank.GameRecord)
			y2023.GET("gameExist", tank.GameExist)
			y2023.GET("wheelWarRanks", tank.WheelWarRanks)
			y2023.GET("finalRanks", tank.FinalRanks2021)
			y2023.GET("aiRanks", tank.AIRanks)

			// 以下是2023年新增接口
			y2023.POST("user/register", tank.Register)
			y2023.POST("user/login", tank.Login)
			y2023.GET("user/emailRegList", tank.List)
			y2023.POST("user/updateJoinStatus", tank.UpdateJoinStatus)
		}
	}

	r.Static("assets", "./static")

	err := r.Run(":" + config.ListenPort)
	if err != nil {
		utils.Error.Println(err)
		panic(err)
	}
}
